class linklist:
    class Node:
        def __init__(self,item = None) -> None:
            self.item = item
            self.next = None
    
    class LinklistIterator:
        def __init__(self,node) -> None:
            self.node = node
        def __next__(self):
            if self.node:
                curNode = self.node
                self.node = curNode.next
                return curNode.item
            else:
                raise StopIteration
    
    def __init__(self,iterable = None) -> None:
        self.head = None
        self.tail = None
        if iterable:
            self.extend(iterable)
    
    def append(self,obj):
        s = linklist.Node(obj)
        if self.head:
            self.tail.next = s
            self.tail = self.tail.next
        else:
            self.head = s
            self.tail = s
        
    def extend(self,iterable):
        for obj in iterable:
            self.append(obj)
    
    def find(self,obj):
        for n in self:
            if n == obj:
                return True
        else:
            return False
    
    def __iter__(self):
        return self.LinklistIterator(self.head)
    
    def __repr__(self) -> str:
        return "<<"+",".join(map(str,self))+">>"
    
# 类似于集合的结构
class HashTable:
    def __init__(self,size = 101) -> None:
        self.size = size
        self.T = [linklist() for i in range(self.size)]

    def h(self,k):#哈希函数
        return k % self.size

    def insert(self,k):
        i = self.h(k)
        if self.find(k):
            print("Duplicated Insert.")
        else:
            self.T[i].append(k)
    def find(self,k):
        i = self.h(k)
        return self.T[i].find(k)


if __name__ == "__main__":
    lk = linklist([1,2,3,4])
    for element in lk:
        print(element)

    ht = HashTable()
    ht.insert(0)
    ht.insert(1)
    ht.insert(0)
    ht.insert(102)
    ht.insert(3)
    print(".".join(map(str,ht.T)))
    print(ht.find(102))